package com.itany.springcloud.consumer.controller;

import com.itany.springcloud.common.entity.User;
import com.itany.springcloud.common.vo.ResponseResult;
import com.itany.springcloud.consumer.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping
    public ResponseResult findAll(){
        return userService.findAll();
    }

    @GetMapping("/{id}")
    public ResponseResult findById(@PathVariable("id") Integer id){
        return userService.findById(id);
    }

    @PostMapping
    public ResponseResult add(User user){
        return userService.add(user.getUsername(),user.getPassword());
    }

    @PostMapping("/add2")
    public ResponseResult add2(User user){
        return userService.add2(user);
    }

//    @PostMapping("/add3")
//    public ResponseResult add3(User user){
//        return userService.add3(user);
//    }

    @DeleteMapping("/{id}")
    public ResponseResult remove(@PathVariable("id") Integer id){
        return userService.remove(id);
    }

    @PutMapping
    public ResponseResult modify(User user){
        return userService.modify(user.getId(),user.getUsername(),user.getPassword());
    }
}
